<?php
	require '../include/library.inc.php';
	require '../include/admin_login.inc.php';
	require '../include/paging.inc.php';

	$sql = "SELECT
				order_id,
				order_date,
				firstname,
				lastname,
				email,
				country,
				continent,
				institution,
				status,
				note,
				price,
				paypal,
				iass,
				culinary,
				dinner,
				allergic,
				lang
				
			FROM
				orders
				
				WHERE del = '0'
				
			  ";
	
	
	if (!isset($_GET['sort'])) $_GET['sort'] = 1;
	if (!isset($_GET['sortBy'])) $_GET['sortBy'] = 1;
	
	$paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(1=>"Подредба"), 20);
	
	$paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(1=>"Номер",3=>"Име",6=>"Държава",7=>"Регион",9=>"Статус",
	2=>"Дата",11=>"Сума",16=>"Алергичен",13=>"IASS/AIS",14=>"Кулинарно шоу",15=>"Гала вечеря"), 30);
	$result = $paging->query();
		
		head_admin("Регистрации");
	?>
			
				<?php if ($_SESSION['message']) { ?>
				<div class="message green">
					<?=$_SESSION['message']?>
				</div>
				<?php unset($_SESSION['message']); } ?>
			
			
				<div class="topbuttons">
					<a href="export_report.php" target="_blank">XLS export</a>
					
				</div>
				<h3>Регистрации (<?=$paging->count()?>)</h3>
				<span>Сортиране</span>
                <?=$paging->displayNext()?>
                <?=$paging->displayNext()?>
                <?=$paging->displayNext()?>
                 <?=$paging->displayNext()?>
                 <?=$paging->displayNext()?>
                <?=$paging->displayNext()?>
                <?=$paging->displayNext()?>
                 <?=$paging->displayNext()?>
                 <?=$paging->displayNext()?>
                <?=$paging->displayNext()?>
                <?=$paging->displayNext()?>
                
				<table id="listing" width="100%" cellpadding="0" cellspacing="0">
					<thead>
                        <tr>
                        	<td>№</td>
                            <td>Име</td>
                            <td>Държава</td>
                            <td>Статус</td>
                            <td>Дата</td>
                            <td>Сума</td>
                            <td>Действия</td>
                        </tr>
                    </thead>
				<tbody>
				<?php
				  
				  
				  $i=1;
				  while ($row = mysql_fetch_object($result)) {				  
				?>
						<tr class="<?=(($i%2)?"none":"zebra")?>">
							<td class="icons" rowspan="2">
                            <?=$row->order_id?>
                            </td>
                            <td>
                            <a href="order_edit.php?order_id=<?=$row->order_id?>" name="order<?=$row->order_id?>" title="Редактирай">
                            <?=sth($row->firstname)?> <?=sth($row->lastname)?></a>,
                            <br />
							<a href="mailto:<?=$row->email?>"><?=$row->email?></a>
                            </td>
							
							<td class="icons">
                               
								<?=$row->country?>,
                                <br />
								<?php if($row->continent == 1){?> Европа <?php }?>
								<?php if($row->continent == 2){?> Извън европа <?php }?>
                                <?php if($row->continent == 3){?> Африка <?php }?>,	<br /> език: <?=$row->lang?>
							</td>
							
							<td class="icons">
                            	<?php if($row->status == 0){?> <b style=" color:#900">Неплатена </b> <?php }?>
                                <?php if($row->status == 4){?> <b style=" color:#900">Грешка при плащане </b> <?php }?>
								<?php if($row->status == 2){?> <b style="color:#093">Платена</b> <?php }?>
                                <?php if($row->status == 1){?> <b style="color:#C60">Отказана</b><?php }?>
							</td>
                            <td class="icons">
								
								<?=date('d.m.Y', strtotime($row->order_date))?>
								
							</td>
							
							<td class="icons">
								
                                <b><?=$row->price?> €</b>
								
								 
								
							</td>
                            <td class="icons" rowspan="2">
                            <a href="order_edit.php?order_id=<?=$row->order_id?>" class="edit" title="Редактирай">Редактирай</a>
                             
                             <a href="send_mail.php?order_id=<?=$row->order_id?>&status=<?=$row->status?>" class="mail" title="Изпрати напомнящ е-мейл">Изпрати мейл</a> 
                             
                            <a onClick="if (window.confirm('Сигурен ли си, че искаш да изтриеш записа?')) { document.location='order_del.php?order_id=<?=$row->order_id?>'; return false; }" class="delete" title="Изтрий">Изтрий</a>
                            </td>
							
						</tr>
                        <tr class="<?=(($i%2)?"none":"zebra")?>" c >
                        	<td >
                            Забележка:<br />

                            <?=$row->note?>
                            </td>
                            
                             <td >
                             <?php if($row->allergic){?><span style="color:#900">Алергичен/a!</span> <?php }?>
                             </td>
                            
                            
                             <td >
                             <?php if($row->iass){?><b>+ IASS/AIS<b> <?php }?>
                             </td>
                            
                            
                             <td >
                             <?php if($row->culinary){?><b>+ Culinary show<b> <?php }?>
                             </td>
                            
                            
                            <td >
                            <?php if($row->dinner){?><b>+ Gala dinner<b> <?php }?>
                            </td>
                        </tr>
                        
			 <?php
				  $i++;    
				} 
			 ?>				  
				</tbody>
			</table>
			
			<div class="pagingwrap"><div class="paging">
				<?=$paging->display()?>
			</div></div>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">

</table>

  
            
<?php
	foot_admin(); 
?>